﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ckknight.StateMachine.ConsoleTestApp
{
    class Program
    {
        enum State { Alpha, Bravo, Exiting }

        static void Main(string[] args)
        {
            var machine = StateMachineBuilder.Create<State, string>(null, StringComparer.OrdinalIgnoreCase)
                .Configure(State.Alpha)
                    .OnEntry(() => Console.WriteLine("Switched to Alpha"))
                    .Permit("switch", State.Bravo)
                    .Permit("bravo", State.Bravo)
                    .Ignore("alpha")
                    .Permit("exit", State.Exiting)
                    .End()
                .Configure(State.Bravo)
                    .OnEntry(() => Console.WriteLine("Switched to Bravo"))
                    .Permit("switch", State.Alpha)
                    .Ignore("bravo")
                    .Permit("alpha", State.Alpha)
                    .Permit("exit", State.Exiting)
                    .End()
                .OnUnhandledTrigger(t => Console.WriteLine("Unknown trigger: {0}", t.Trigger))
                .CreateFactory()
                .Generate(State.Alpha);

            while (true)
            {
                Console.WriteLine(machine);

                machine.Fire(Console.ReadLine().Trim());

                if (machine.IsInState(State.Exiting))
                {
                    break;
                }
            }
        }
    }
}
